<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改商品')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-shangping-edit" th:object="${shangpinguanli}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">商品名
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinming" th:field="*{shangpinming}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group" id="shengchanchangshang">
            <label class="col-sm-3 control-label">生产厂家
                ：</label>
            <div class="col-sm-8">
                <input name="shengchanchangshang" th:field="*{shengchanchangshang}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品类别
                ：</label>
            <div class="col-sm-8">
                <!--                <input name="shangpinleibie" class="form-control" type="text">-->
                <select name="shangpinleibie" th:field="*{shangpinleibie}" class="form-control">
                    <option value="防火门（左扇）" th:text="'防火门（左扇）'"></option>
                    <option value="防火门（右扇）" th:text="'防火门（右扇）'"></option>
                    <option value="防火门（整套门）" th:text="'防火门（整套门）'"></option>
                    <option value="防火门（门框）" th:text="'防火门（门框）'"></option>
                    <option value="防火锁" th:text="'防火锁'"></option>
                    <option value="闭门器" th:text="'闭门器'"></option>
                    <option value="拉爆盖" th:text="'拉爆盖'"></option>
                </select>
            </div>
        </div>
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">商品编号
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinbianhao" readonly th:field="*{shangpinbianhao}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">规格宽
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinguigekuan" onblur="changeselect(this.value)" th:field="*{shangpinguigekuan}"
                       class="form-control"
                       type="number">
                <script>
                    function changeselect(value) {
                        document.getElementById("teshu1").hidden = Number(value) < 1000;
                        document.getElementById("teshu2").hidden = Number(value) < 1000;
                    }
                </script>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">规格高
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinguigegao" th:field="*{shangpinguigegao}" class="form-control"
                       type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开向
                ：</label>
            <div class="col-sm-8">
                <!--                                <input name="shangpinkaixiang" th:field="*{shangpinkaixiang}" class="form-control"-->
                <!--                                       type="text">-->
                <select name="shangpinkaixiang" th:field="*{shangpinkaixiang}" class="form-control">
                    <option value="外左开" th:text="'外左开'"></option>
                    <option value="外右开" th:text="'外右开'"></option>
                    <option value="外双开" th:text="'外双开'" id="teshu1"></option>
                    <option value="内左开" th:text="'内左开'"></option>
                    <option value="内外开" th:text="'内外开'"></option>
                    <option value="内双开" th:text="'内双开'" id="teshu2"></option>
                    <option value="卷闸门" th:text="'卷闸门'"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品图片
                ：</label>
            <div class="col-sm-8">
                <input type="hidden" name="shangpintupian" th:field="*{shangpintupian}">
                <div class="file-loading">
                    <input class="form-control file-upload" id="shangpintupian" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品进货价
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinjinhuojia" th:field="*{shangpinjinhuojia}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品售价
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinshoujia" th:field="*{shangpinshoujia}" class="form-control"
                       type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "cangku/shangpin";
    $("#form-shangping-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-shangping-edit').serialize());
        }
    }

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        $(this).fileinput({
            'uploadUrl': ctx + 'common/upload',
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(this).fileinput('_initFileActions');
    });
</script>
</body>
</html>